package cn.hy.tiny.demo.parse;

import cn.hy.tiny.demo.core.Configuration;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author huang.xy
 * @Description TODO
 */
public  class ParameterMappingTokenHandler implements TokenHandler {

    private final List<ParameterMapping> parameterMappings = new ArrayList<>();

    public ParameterMappingTokenHandler() {
    }

    public List<ParameterMapping> getParameterMappings() {
        return parameterMappings;
    }

    @Override
    public String handleToken(String content) {
        parameterMappings.add(buildParameterMapping(content));
        return "?";
    }

    private ParameterMapping buildParameterMapping(String content) {
        Map<String, String> propertiesMap = new ParameterExpression(content);
        String property = propertiesMap.get("property");
        ParameterMapping.Builder builder = new ParameterMapping.Builder(property);
        return builder.build();
    }
}